package com.tansun.exceltohtml.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 作者：WGS
 * 微信：w1150111308
 * Q  Q：1150111308
 * 邮箱：gosse0405@163.com
 */
@Component
public class ScheduledTasks {

	@Value("${uploadPath}")
	private String uploadPath;

	@Scheduled(cron = "0 59 23 ? * *")
	public void reportCurrentTime() {
		if (delFile(new File(System.getProperty("user.dir") + uploadPath))) {
			System.out.println("删除成功");
		}
	}

	/**
	 * 删除文件夹及所有文件
	 * @param file
	 * @return
	 */
	private boolean delFile(File file) {
		if (!file.exists()) {
			return false;
		}

		if (file.isDirectory()) {
			File[] files = file.listFiles();
			for (File f : files) {
				delFile(f);
			}
		}
		return file.delete();
	}
}
